import java.util.Arrays;

/**
 * @author hewei
 * @version 1.0
 * @description: 1093. 大样本统计
 * @date 2022/11/18 14:24
 */

public class SampleStats {

    public static void main(String[] args) {
        int[] count = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        System.out.println(Arrays.toString(new SampleStats().sampleStats(count)));
    }

    public double[] sampleStats(int[] count) {
        int n = count.length;
        int max = -1, min = 256, maxSeq = 0;
        long sum = 0L, countSum = 0;
        for (int i = 0; i < n; i++) {
            sum += (long) i * count[i];
            countSum += count[i];
            if (count[i] != 0) {
                max = Math.max(max, i);
                min = Math.min(min, i);
            }
            if (count[i] > count[maxSeq]) {
                maxSeq = i;
            }
        }
        double mean = (double) sum / countSum;
        long target = countSum / 2;
        long temp = 0L;
        double median = -1, last = -1;
        for (int i = 0; i < n; i++) {
            temp += count[i];
            if (temp > target) {
                if (countSum % 2 == 1) {
                    median = i;
                } else if (last == -1) {
                    median = i;
                } else {
                    median = (last + i) / (double) 2;
                }
                break;
            } else if (temp == target && last == -1 && countSum % 2 == 0) {
                last = i;
            }
        }
        return new double[]{min, max, mean, median, count[maxSeq]};
    }
}
